//
//  MTMainViewController.swift
//  MTWeiBo
//
//  Created by user on 2017/7/22.
//  Copyright © 2017年 itcast. All rights reserved.
//

import UIKit

class MTMainViewController: UITabBarController {

    override func viewDidLoad() {
        super.viewDidLoad()

        //使用kvc给指定属性赋值
        let MTtabbar = MTTabBar()
        self.setValue(MTtabbar, forKey: "tabBar")
        
        //设置闭包
        MTtabbar.composeButtenClosure = {[unowned self] in
            print("闭包")
            //循环引用
            print(self)
        }
        
        //设置代理
        MTtabbar.mtTabbarDelegate = self
        
        addChildViewController(childController: MTHomeTableViewController(), title: "首页", imageName: "tabbar_home")
        addChildViewController(childController: MTMessageTableViewController(), title: "消息", imageName: "tabbar_message_center")
        addChildViewController(childController: MTDiscoverTableViewController(), title: "发现", imageName: "tabbar_discover")
        addChildViewController(childController: MTMineTableViewController(), title: "我的", imageName: "tabbar_profile")
        
    }

    func addChildViewController(childController: UIViewController,title: String,imageName: String) {
        
        //设置标题
        childController.title = title
        //设置图片
        childController.tabBarItem.image = UIImage(named: imageName)?.withRenderingMode(.alwaysOriginal)
        childController.tabBarItem.selectedImage = UIImage(named: imageName + "_selected")?.withRenderingMode(.alwaysOriginal)
       //标题颜色
    childController.tabBarItem.setTitleTextAttributes([NSForegroundColorAttributeName:UIColor.orange], for: .selected)
        //修改文字大小
        childController.tabBarItem.setTitleTextAttributes([NSFontAttributeName:UIFont.systemFont(ofSize: 12)], for: .normal)
        let nav = MTNavViewController(rootViewController: childController)
        
        addChildViewController(nav)
        
        
    }
    

}

extension MTMainViewController: MTTabBarDelegate{

    func clickComposeButtonOperation() {
        print("代理")
    }
}
